package edu.lsnu.equipment_management_system.service.impl;

import edu.lsnu.equipment_management_system.mapper.select.paging.AdminOptionMapperWithPaging;
import edu.lsnu.equipment_management_system.pojo.domain.PageBean;
import edu.lsnu.equipment_management_system.pojo.domain.PageBeanDeal;
import edu.lsnu.equipment_management_system.pojo.vo.out.admin.AdminMsgInRepairVo;
import edu.lsnu.equipment_management_system.pojo.vo.out.admin.AdminMsgInVo;
import edu.lsnu.equipment_management_system.pojo.vo.out.admin.AdminUseRecordVo;
import edu.lsnu.equipment_management_system.pojo.vo.sql_conditions.PageBeginAndPageSizeVo;
import edu.lsnu.equipment_management_system.pojo.vo.sql_conditions.PageBeginPageSizeAndEquipmentNoVo;
import edu.lsnu.equipment_management_system.service.AdminOptionService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author mzy
 * @Description 管理员等待审核的列表
 * @date 2018/11/23
 */
@Service
// 将page.size注入进来
@Data
@PropertySource({"classpath:resource.properties"})
@ConfigurationProperties(prefix = "page.admin")
public class AdminOptionServiceImpl implements AdminOptionService {
    private Integer size;
    @Autowired
    AdminOptionMapperWithPaging adminOptionMapperWithPaging;

    /**
     * @Description 购入的List
     * @author mzy
     * @time 2018-11-24
     * @see 
     * @return   edu.lsnu.equipment_management_system.pojo.domain.PageBean<edu.lsnu.equipment_management_system.pojo.vo.out.admin.AdminMsgInVo>
     * @params  [currentPage]
     */
    @Override
    public PageBean<AdminMsgInVo> getEquipmentPurchaseBasicListVo(Integer currentPage) {
        // 获得总count
        Integer count = adminOptionMapperWithPaging.getEquipmentPurchaseBasicListVoCount();
        // 构造pageBean
        PageBean<AdminMsgInVo> pageBeanContain = new PageBean<>();

        PageBean<AdminMsgInVo> pageBean = (PageBean<AdminMsgInVo>) PageBeanDeal.getPageBean(count, currentPage, this.size, pageBeanContain);


        // 查询当前页的List。
        PageBeginAndPageSizeVo pageBeginAndPageSizeVo = new PageBeginAndPageSizeVo();
        // 当前页开始的条数：(当前页 - 1) * 页容量
        Integer pageBegin = (pageBean.getCurrentPage() - 1)*pageBean.getPageSize();
        pageBeginAndPageSizeVo.setPageBegin(pageBegin);
        pageBeginAndPageSizeVo.setPageSize(pageBean.getPageSize());
        List<AdminMsgInVo> equipmentPurchaseBasicListVo =
                adminOptionMapperWithPaging.getEquipmentPurchaseBasicListVo(pageBeginAndPageSizeVo);

        pageBean.setContent(equipmentPurchaseBasicListVo);

        return pageBean;
    }

    /**
     * @Description 调入的List
     * @author mzy
     * @time 2018-11-24
     * @see
     * @return   edu.lsnu.equipment_management_system.pojo.domain.PageBean<edu.lsnu.equipment_management_system.pojo.vo.out.admin.AdminMsgInVo>
     * @params  [currentPage]
     */
    @Override
    public PageBean<AdminMsgInVo> getEquipmentTransferInBasicListVo(Integer currentPage) {
        // 获得总count
        Integer count = adminOptionMapperWithPaging.getEquipmentTransferInBasicListVoCount();
        // 构造pageBean
        PageBean<AdminMsgInVo> pageBeanContain = new PageBean<>();

        PageBean<AdminMsgInVo> pageBean = (PageBean<AdminMsgInVo>) PageBeanDeal.getPageBean(count, currentPage, this.size, pageBeanContain);


        // 查询当前页的List。
        PageBeginAndPageSizeVo pageBeginAndPageSizeVo = new PageBeginAndPageSizeVo();
        // 当前页开始的条数：(当前页 - 1) * 页容量
        Integer pageBegin = (pageBean.getCurrentPage() - 1)*pageBean.getPageSize();
        pageBeginAndPageSizeVo.setPageBegin(pageBegin);
        pageBeginAndPageSizeVo.setPageSize(pageBean.getPageSize());
        List<AdminMsgInVo> equipmentTransferInBasicListVo =
                adminOptionMapperWithPaging.getEquipmentTransferInBasicListVo(pageBeginAndPageSizeVo);

        pageBean.setContent(equipmentTransferInBasicListVo);

        return pageBean;
    }

    /**
     * @Description 维修维护的List
     * @author mzy
     * @time 2018-11-24
     * @see
     * @return   edu.lsnu.equipment_management_system.pojo.domain.PageBean<edu.lsnu.equipment_management_system.pojo.vo.out.admin.AdminMsgInVo>
     * @params  [currentPage]
     */
    @Override
    public PageBean<AdminMsgInRepairVo> getEquipmentRepairBasicListVo(Integer currentPage) {
        // 获得总count
        Integer count = adminOptionMapperWithPaging.getEquipmentRepairBasicListVoCount();
        // 构造pageBean
        PageBean<AdminMsgInRepairVo> pageBeanContain = new PageBean<>();

        PageBean<AdminMsgInRepairVo> pageBean = (PageBean<AdminMsgInRepairVo>) PageBeanDeal.getPageBean(count, currentPage, this.size, pageBeanContain);


        // 查询当前页的List。
        PageBeginAndPageSizeVo pageBeginAndPageSizeVo = new PageBeginAndPageSizeVo();
        // 当前页开始的条数：(当前页 - 1) * 页容量
        Integer pageBegin = (pageBean.getCurrentPage() - 1)*pageBean.getPageSize();
        pageBeginAndPageSizeVo.setPageBegin(pageBegin);
        pageBeginAndPageSizeVo.setPageSize(pageBean.getPageSize());
        List<AdminMsgInRepairVo> equipmentRepairBasicListVo =
                adminOptionMapperWithPaging.getEquipmentRepairBasicListVo(pageBeginAndPageSizeVo);

        pageBean.setContent(equipmentRepairBasicListVo);

        return pageBean;
    }

    /**
     * @Description 调出的List
     * @author mzy
     * @time 2018-11-24
     * @see 
     * @return   edu.lsnu.equipment_management_system.pojo.domain.PageBean<edu.lsnu.equipment_management_system.pojo.vo.out.admin.AdminMsgInVo>
     * @params  [currentPage]
     */
    @Override
    public PageBean<AdminMsgInVo> getEquipmentTransferOutBasicListVo(Integer currentPage) {
        // 获得总count
        Integer count = adminOptionMapperWithPaging.getEquipmentTransferOutBasicListVoCount();
        // 构造pageBean
        PageBean<AdminMsgInVo> pageBeanContain = new PageBean<>();

        PageBean<AdminMsgInVo> pageBean = (PageBean<AdminMsgInVo>) PageBeanDeal.getPageBean(count, currentPage, this.size, pageBeanContain);


        // 查询当前页的List。
        PageBeginAndPageSizeVo pageBeginAndPageSizeVo = new PageBeginAndPageSizeVo();
        // 当前页开始的条数：(当前页 - 1) * 页容量
        Integer pageBegin = (pageBean.getCurrentPage() - 1)*pageBean.getPageSize();
        pageBeginAndPageSizeVo.setPageBegin(pageBegin);
        pageBeginAndPageSizeVo.setPageSize(pageBean.getPageSize());
        List<AdminMsgInVo> equipmentTransferOutBasicListVo =
                adminOptionMapperWithPaging.getEquipmentTransferOutBasicListVo(pageBeginAndPageSizeVo);

        pageBean.setContent(equipmentTransferOutBasicListVo);

        return pageBean;
    }

    /**
     * @Description 损毁的List
     * @author mzy
     * @time 2018-11-24
     * @see
     * @return   edu.lsnu.equipment_management_system.pojo.domain.PageBean<edu.lsnu.equipment_management_system.pojo.vo.out.admin.AdminMsgInVo>
     * @params  [currentPage]
     */
    @Override
    public PageBean<AdminMsgInVo> getEquipmentDamageBasicListVo(Integer currentPage) {
        // 获得总count
        Integer count = adminOptionMapperWithPaging.getEquipmentDamageBasicListVoCount();
        // 构造pageBean
        PageBean<AdminMsgInVo> pageBeanContain = new PageBean<>();

        PageBean<AdminMsgInVo> pageBean = (PageBean<AdminMsgInVo>) PageBeanDeal.getPageBean(count, currentPage, this.size, pageBeanContain);


        // 查询当前页的List。
        PageBeginAndPageSizeVo pageBeginAndPageSizeVo = new PageBeginAndPageSizeVo();
        // 当前页开始的条数：(当前页 - 1) * 页容量
        Integer pageBegin = (pageBean.getCurrentPage() - 1)*pageBean.getPageSize();
        pageBeginAndPageSizeVo.setPageBegin(pageBegin);
        pageBeginAndPageSizeVo.setPageSize(pageBean.getPageSize());
        List<AdminMsgInVo> equipmentDamageBasicListVo =
                adminOptionMapperWithPaging.getEquipmentDamageBasicListVo(pageBeginAndPageSizeVo);

        pageBean.setContent(equipmentDamageBasicListVo);

        return pageBean;
    }

    /**
     * @Description 获得所有待审核的运行使用
     * @author mzy
     * @time 2018-11-26
     * @see
     * @return   edu.lsnu.equipment_management_system.pojo.domain.PageBean<edu.lsnu.equipment_management_system.pojo.vo.out.admin.AdminUseRecordVo>
     * @params  [currentPage]
     */
    @Override
    public PageBean<AdminUseRecordVo> getEquipmentUseRecordVo(Integer currentPage) {
        // 获得总count
        Integer count = adminOptionMapperWithPaging.getEquipmentUseRecordVoCount();
        // 构造pageBean
        PageBean<AdminUseRecordVo> pageBeanContain = new PageBean<>();

        PageBean<AdminUseRecordVo> pageBean = (PageBean<AdminUseRecordVo>) PageBeanDeal.getPageBean(count, currentPage, this.size, pageBeanContain);

        // 查询当前页的List。
        PageBeginAndPageSizeVo pageBeginAndPageSizeVo = new PageBeginAndPageSizeVo();
        // 当前页开始的条数：(当前页 - 1) * 页容量
        Integer pageBegin = (pageBean.getCurrentPage() - 1)*pageBean.getPageSize();
        pageBeginAndPageSizeVo.setPageBegin(pageBegin);
        pageBeginAndPageSizeVo.setPageSize(pageBean.getPageSize());
        List<AdminUseRecordVo> equipmentUseRecordVo =
                adminOptionMapperWithPaging.getEquipmentUseRecordVo(pageBeginAndPageSizeVo);

        pageBean.setContent(equipmentUseRecordVo);

        return pageBean;

    }

    /**
     * @Description 通过equipmentNo，获得一个设备的使用记录
     * @author mzy
     * @time 2018-11-24
     * @see 
     * @return   edu.lsnu.equipment_management_system.pojo.domain.PageBean<edu.lsnu.equipment_management_system.pojo.vo.out.admin.AdminUseRecordVo>
     * @params  [currentPage, equipmentNo]
     */
    @Override
    public PageBean<AdminUseRecordVo> getEquipmentUseRecordVoByEquipmentNo(Integer currentPage, String equipmentNo) {
        // 获得总count
        Integer count = adminOptionMapperWithPaging.getEquipmentUseRecordVoByEquipmentNoCount(equipmentNo);
        // 构造pageBean
        PageBean<AdminUseRecordVo> pageBeanContain = new PageBean<>();

        PageBean<AdminUseRecordVo> pageBean = (PageBean<AdminUseRecordVo>) PageBeanDeal.getPageBean(count, currentPage, this.size, pageBeanContain);


        // 查询当前页的List。
        PageBeginPageSizeAndEquipmentNoVo pageBeginPageSizeAndEquipmentNoVo = new PageBeginPageSizeAndEquipmentNoVo();
        // 当前页开始的条数：(当前页 - 1) * 页容量
        Integer pageBegin = (pageBean.getCurrentPage() - 1)*pageBean.getPageSize();
        pageBeginPageSizeAndEquipmentNoVo.setPageBegin(pageBegin);
        pageBeginPageSizeAndEquipmentNoVo.setPageSize(pageBean.getPageSize());
        pageBeginPageSizeAndEquipmentNoVo.setEquipmentNo(equipmentNo);

        List<AdminUseRecordVo> equipmentUseRecordVo =
                adminOptionMapperWithPaging.getEquipmentUseRecordVoByEquipmentNo(pageBeginPageSizeAndEquipmentNoVo);

        pageBean.setContent(equipmentUseRecordVo);

        return pageBean;
    }

}
